<template>
    <div id="comment">
        <div class="ctop">
            <router-link to="/">首页</router-link>
            <i class="el-icon-arrow-right"></i>
            <span>评论</span>
        </div>
        <ul class="content">
            <li v-for="item in data.results" :key="item.pjid">
                <div class="headpic" ><img :src="item.head_pic" alt=""></div>
                <div>
                <div class="msg">
                    <div class="left">
                        <div class="name">{{item.user_name}}</div>
                        <div class="time">{{item.appraise_time}}</div>
                    </div>
                    <div class="right">
                        <div class="location">{{item.delivery_place}}</div>
                        <div class="way">{{item.delivery_mode}}</div>
                    </div>
                </div>
                <div class="appraise">{{item.user_appraise}}</div>
                <div class="answer">{{item.customer_service_answer}}</div>
                </div>
            </li>
        </ul>

             <!-- 底部分页 element-->
             <div  class="paging">
             <el-pagination
                prev-text='上一页'
                next-text='下一页'
                @current-change="handleCurrentChange"
                :current-page="Number($route.query.page)"
                background
                layout="prev, pager, next,jumper"
                :total="rowcount*10">
             </el-pagination>
             </div>
           
    </div>
</template>

<script>

    export default {
        created(){
        //获取$store.state.page的值赋给page
         this.page=this.$store.state.page
          
        
        },
        data() {
            return {
                data:[],
                // 总页数
                rowcount:0,
                //默认显示第一页
                currentPage: 1,
                // 当前页数
                page:1,
                // 图片地址
                photo:[],
                cs:0,
                
            }
        },
        mounted(){
        console.log('测试开始1：',this.$store.state.page,typeof this.$store.state.page);
        console.log('测试开始2：',this.page,typeof this.page);

         
         
            this.axios.get(`/comments?page=${this.page}`).then(res=>{
                this.data=res.data
                // 总页数赋给rowcount
                this.rowcount=res.data.pagecount
                // console.log(res);
            })


           // 随机图片接口
            let url='http://localhost:8080/shuiji/random.php?return=json';
              this.axios.get(url).then(res=>{
            //    console.log(res);
            //    this.data.push=res.data.data.url
               this.photo=res.data.imgurl
           }) 
          
            
        },
        methods: {
            handleCurrentChange(val) {
            // console.log(`当前页: ${val}`);
            this.currentPage = val;    //动态改变
            this.axios.get(`/comments?page=${this.currentPage}`).then(res=>{
                // console.log('res :>> ', res);
                this.data=res.data
                // 当前页数赋给page
                this.$store.commit('uPage', this.currentPage)
                // 点击后跳转相对于的页数的页面
                // console.log(this.currentPage);
                this.$router.push(`/comments?page=${this.currentPage}`)

                // 点击后到页面顶部
                window.scrollTo(0,0)
            })
            },
            sjphone(){
              
            }
        },
        watch: {
            // 监听到跳转就改变$store里uPage的值为1页
            '$route' (to, from){
                this.$store.commit('uPage', 1)
                console.log(to, from);
            }
        },
    }
</script>

<style lang="scss" >
.paging {
 >.el-pagination >.btn-prev>span , .el-pagination >.btn-next>span{
    width: 75px;
}
}
//修改鼠标滑过的颜色
.paging {

     >.el-pagination.is-background .el-pager li:hover {
    　　color: #ff6e6e;
    }
     >.el-pagination.is-background .el-pager li:not(.disabled):hover {
    　　color: #ff6e6e;
    }
     >.el-pagination.is-background .el-pager li:not(.disabled).active:hover {
    　　background-color: #ff6e6e;
    }
     >.el-pagination.is-background .el-pager li:not(.disabled).active {
        background-color: #ff6e6e;   // 进行修改背景
    }

}
    
</style>

<style lang="scss" scoped>
.paging{
    padding: 15px 0;
}
.el-pagination button,  span{
width: 75px;
}
.el-pagination{
   width: 640px;
   margin: 0 auto;  
   font-weight: normal;
}
#comment{
    width: 1200px;
    // height: 400px;
    // background-color: beige;
    margin: 0px auto 20px;
}
.ctop{
    padding: 40px 0 20px 0;
    font-size: 16px;
    font-weight: 400;
    >a{
        color: #808080;
        padding-right: 10px;
    }
    >i{
    margin-right: 10px;
    }
    >span{
        color:#333;
    }
}
.content{
    padding: 20px;
    background-color: #fff;
    >li{
        border-bottom: 1px solid #ebebeb;
        // position: relative;
        display: flex;

        >.headpic{
        width: 56px;
        height: 56px;
        // float: left;
        // position: absolute;
        // top: 0;
        // left: 0;
        >img{
            width: 56px;
            height: 56px;
            border-radius:100px;
            margin: 8px;
        }
        }
       >div{
         >.msg{
            width: 1084px;
            height: 50px;
            display: flex;
            margin-left: 28px;
            justify-content: space-between;
            line-height: 50px;
            >.left{
                >.name{
                    font-size: 16px;
                    font-family: PingFangSC-Semibold;
                    font-weight: 600;
                    color: #ff6e6e;
                    display: inline-block;
                }
                >.time{
                    font-size: 14px;
                    display: inline-block;
                    padding-left: 28px;
                }
            }
            >.right{
                >.location{
                    display: inline-block;
                    margin-right: 40px;
                    font-size: 12px;
                }
                >.way{
                    display: inline-block;
                    font-size: 12px;
                }
            }
        }
        >.appraise{
            width: 1064px;
            background-color: #f4f4f4;
            margin-left: 28px;
            padding: 15px 20px;
            line-height: 22px;
        }
        .answer{
            width: 1084px;
            margin-left: 28px;
            padding: 15px 0 20px 20px;
        }
       }
    }
    
}
</style>